package com.spring.vencent.service.impl;

import javax.naming.NamingException;
import javax.naming.Reference;
import javax.naming.Referenceable;
import javax.naming.StringRefAddr;

import com.spring.vencent.factory.DBServiceFactory;
import com.spring.vencent.service.DBService;

public class DBServiceImpl implements Referenceable, DBService {
	private String location = "mydb//local:3306/base_test";

	private String state = "start";

	@Override
	public String getLocation() {
		return location;
	}

	@Override
	public String getState() {
		return state;
	}

	@Override
	public void accessDB() {
		if(state.equals("start")){
			System.out.println("数据库服务开启");
		}else{
			System.out.println("数据库未开启");
		}
	}

	@Override
	public void setProperty(int index, String property) {
		if (index == 0){
			location = property;  
		}else{
			state = property;
		}
	}

	@Override
	public Reference getReference() throws NamingException {
		Reference ref = new Reference(getClass().getName(), DBServiceFactory.class.getName(), null);
		//设置属性
		ref.add(new StringRefAddr("location", location));
		ref.add(new StringRefAddr("state", state));
		return ref;
	}

}
